import pygame

from Data.TextRender import blit_text
from Data.Variable import SCREEN_WIDTH


class SysBaseDialog:
    def __init__(self, text_list: list, font):
        self.text_list = text_list
        self.current_id = 0
        self.dialog_image = pygame.image.load("./Resources/images/dialog/sys_dialog.png")
        self.font = font
        (x, y, w, h) = self.dialog_image.get_rect()
        self.pos_x = int((SCREEN_WIDTH - w) / 2) + 35
        self.pos_y = 35
        self.finished = False

    def draw(self, current_surface):
        if self.current_id >= len(self.text_list):
            return
        current_surface.blit(self.dialog_image, (self.pos_x, self.pos_y))
        blit_text(current_surface, self.text_list[self.current_id],
                  (self.pos_x + 30, self.pos_y + 50), self.font)

    def is_finish(self):
        return self.finished

    def next_text(self):
        self.current_id += 1
        if self.current_id > len(self.text_list):
            self.finished = True


class ActorBaseDialog(SysBaseDialog):
    def __init__(self, actor, text_list: list, font):
        self.text_list = text_list
        self.actor = actor
        self.current_id = 0
        self.dialog_image = pygame.image.load("./Resources/images/dialog/actor_dialog.png")
        self.finished = False
        self.font = font

    def draw(self, current_surface, x, y):
        if self.current_id >= len(self.text_list):
            return
        temp_x = self.actor.pos_x - x + 5
        temp_y = self.actor.pos_y - y - 55
        current_surface.blit(self.dialog_image, (temp_x, temp_y))
        blit_text(current_surface, self.text_list[self.current_id],
                  (temp_x + 10, temp_y + 10), self.font)
